//
//  ScreenViewController.m
//  JoyFulFurnishing
//
//  Created by 李书勋 on 14/12/18.
//  Copyright (c) 2014年 apple. All rights reserved.
//

#import "ScreenViewController.h"
#import "DataClass.h"
@interface ScreenViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (retain, nonatomic)NSMutableArray *styleArr;
@property (retain, nonatomic)NSMutableArray *colorArr;
@property (retain, nonatomic)NSMutableArray *spaceArr;
@property (retain, nonatomic)UITableView *tableView;
@property (retain, nonatomic)NSMutableArray *destArr;
@property (retain, nonatomic)NSString *str;
@end

@implementation ScreenViewController
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.styleArr = [NSMutableArray arrayWithObjects:@"任意风格",@"现代",@"简约",@"日式",  @"地中海", @"欧式", @"中式", @"新古典", @"宜家", @"田园", @"小资",@"美式",nil];
        
        self.colorArr = [NSMutableArray arrayWithObjects:@"全部颜色",@"白色", @"原木色", @"红色", @"紫色", @"春色", @"黑白", @"黄色", @"粉色", @"蓝色", @"绿色", nil];
        self.spaceArr = [NSMutableArray arrayWithObjects:@"任意空间", @"玄关", @"客厅", @"餐厅", @"卧室", @"厨房", @"书房", @"儿童房" @"卫生间", @"阳台",nil];
        //DataClass *dataClass = [[DataClass alloc] init];
        //self.spaceArr = dataClass.provinceArr;
        self.destArr = self.spaceArr;}
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 设置 导航栏 标题
    self.navigationItem.title = @"筛选";
    //添加 导航栏 的左右按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"重置" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonClicked:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonClicked:)];
    NSArray *arr = [NSArray arrayWithObjects:@"全部空间",@"全部风格", @"全部颜色", nil];
    // 添加 segmentControl
    UISegmentedControl *segmenteControl = [[UISegmentedControl alloc] initWithItems:arr];
    segmenteControl.frame = CGRectMake(10, 74, 355, 30);
    segmenteControl.tintColor = [UIColor orangeColor];
    [self.view addSubview:segmenteControl];
    [segmenteControl release];
    // 添加 事件
    [segmenteControl addTarget:self action:@selector(segmentedClickedAction:) forControlEvents:UIControlEventValueChanged];
    
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 104, 355, 667 - 104)style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self.view addSubview:self.tableView];
    [_tableView release];
    
}
- (void)segmentedClickedAction:(UISegmentedControl *)segmented
{
    
        switch (segmented.selectedSegmentIndex) {
            case 0:
                self.destArr = self.spaceArr;
                [self.tableView reloadData];
                break;
            case 1:
                self.destArr = self.styleArr;
                [self.tableView reloadData];
                break;
            case 2:
                self.destArr = self.colorArr;
                [self.tableView reloadData];
                break;
            default:
                break;
        }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    self.str = [self.destArr objectAtIndex:indexPath.row];
}
- (void)rightBarButtonClicked:(UIBarButtonItem *)item
{
    self.changeName(self.str);
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)leftBarButtonClicked:(UIBarButtonItem *)item
{
    // 重置功能
    
    
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.destArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"screen"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"screen"] autorelease];
    }
    cell.textLabel.text = [self.destArr objectAtIndex:indexPath.row];
    return cell;
}
- (void)dealloc
{
   
    [_styleArr release];
    [_colorArr release];
    [super dealloc];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
